#include "particle.h"
#include "scene.h"

Particle::Particle(void)
{
}

Particle::~Particle(void)
{
}

Particle::Particle(Vector3 _origen, Vector3 _velocidad, unsigned long _birth, unsigned long _ttl, Vector2 _size)
{
	origen = _origen;
	velocidad = _velocidad;
	birth = _birth;
	ttl = _ttl;
	posicion = origen;
	size = _size;
}

void Particle::render()
{
	Scene *s = Scene::getScene();
	Camera * cam = s->getCamera();
	
	Vector3 top = cam->getLocalVector(Vector3(0,1,0));
	Vector3 right = cam->getLocalVector(Vector3(1,0,0));
	
	Vector3 rightTop  =  right + top;
	Vector3 rightDown =  right - top;

	rightTop.normalize();
	rightDown.normalize();
	
	Vector3 downLeft  =  posicion - rightTop*size.x;
	Vector3 downRight =  posicion + rightDown*size.x;
	Vector3 topRight  =  posicion+velocidad*size.y + rightTop*size.x;
	Vector3 topLeft	  =  posicion+velocidad*size.y - rightDown*size.x;


	glTexCoord2d(0,0); glVertex3f(downLeft.x, downLeft.y, downLeft.z);
	glTexCoord2d(1,0); glVertex3f(downRight.x, downRight.y, downRight.z);
	glTexCoord2d(1,1); glVertex3f(topRight.x, topRight.y, topRight.z);
	glTexCoord2d(0,1); glVertex3f(topLeft.x, topLeft.y, topLeft.z);


}